﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XcoAppSpaces.Core.Ports;

namespace XcoAppSpaces.Core
{
	public static class PortExtensions
	{
		public static void Send<T>(this Port<T> port, T item)
		{
			try
			{
				port.PostAndAwaitSent(item).Wait();
			}
			catch (AggregateException ex)
			{
				throw ex.InnerException; //unpack xco exception
			}
		}

		public static void Send<T>(this Port<T> port, T item, IPort<Exception> errorPort)
		{
			try
			{
				port.PostAndAwaitSent(item, errorPort).Wait();
			}
			catch (AggregateException ex)
			{
				throw ex.InnerException; //unpack xco exception
			}
		}
	}
}
